<?php
namespace app\admin\controller;

use app\BaseController;
use app\admin\model\user;
use think\facade\Request;
use think\facade\Session;
use think\facade\View;

class Login extends BaseController
{
    public function index()
    {
        if(request()->isPost()){
            $data = request()->post();
            $data['password'] = encryption($data['password']);
            $userInfo   = User::findUserInfoByUser(new user(),$data);
            
            if($userInfo){
                Session('userInfo',serialize($userInfo));
                Session('userId',$userInfo['id']);
                $this->success('登录成功',url('admin/index/index'));
            }else{
                $this->error('用户名或密码错误');
            }
        }
        return View::fetch();
    }
    public function loginOut()
    {

    }
}